#include "mq_connection.hpp"

int main(){
    //1. 创建 连接对象
        //创建异步线程给到连接
    mq::AsyncWorker::ptr awp = std::make_shared<mq::AsyncWorker>();

    mq::Connection::ptr conn = std::make_shared<mq::Connection>("127.0.0.1",8085,awp);

    //2. 通过连接，创建信道对象
    mq::Channel::ptr channel =  conn->openChannel();

    //3. 通过信道，创建交换机，队列，绑定信息
        //map对象
    google::protobuf::Map<std::string,std::string> tmp_map;
        //创建交换机
    channel->declareExchange("exchange1",mq::ExchangeType::TOPIC,true,false,tmp_map);
        //创建队列1
    channel->declareQueue("queue1",true,false,false,tmp_map);
        //创建队列2
    channel->declareQueue("queue2",true,false,false,tmp_map);
        //将 交换机1 和 队列1 / 2 绑定，并设置binding_Key
    channel->queueBind("exchange1","queue1","queue1");
    channel->queueBind("exchange1","queue2","news.music.#");

    // DLOG("设备构建完成!");

    //4. 循环向交换机发布10条消息
    for(int i = 1;i <= 10;i++){
        mq::BasicProperties bp;
        bp.set_id(mqhelper::UUIDHelper::uuid());
        bp.set_delivery_mode(mq::DeliveryMode::DURABLE);
        bp.set_routing_key("news.music.pop");
        channel->basicPublish("exchange1", &bp, "Hello World-" + std::to_string(i));
    }
    mq::BasicProperties bp;
    bp.set_id(mqhelper::UUIDHelper::uuid());
    bp.set_delivery_mode(mq::DeliveryMode::DURABLE);
    bp.set_routing_key("news.music.sport");
    channel->basicPublish("exchange1", &bp, "Hello Bite");

    
    bp.set_routing_key("news.sport");
    channel->basicPublish("exchange1", &bp, "Hello chileme?");
    // DLOG("关闭信道！");
    conn->closeChannel(channel);
    return 0;
}